package com.itheima.utils;

import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;

/**
 * @author FCJ
 * @date 2020-01-07 16:17
 */
public class SMSUtils1 {
    public static final String VALIDATE_CODE = "SMS_181862539";//发送短信验证码
    public static final String ORDER_NOTICE = "SMS_181862539";//体检预约成功通知
    public static void sendSms(String templateCode,String PhoneNumbers,  String code) {

        DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "LTAI4Fd6SYeAqguQZppaNps7", "lNDcSzfE23VT2iVjhp2FGihdNDuFbU");
        IAcsClient client = new DefaultAcsClient(profile);

        CommonRequest request = new CommonRequest();
        request.setMethod(MethodType.POST);
        request.setDomain("dysmsapi.aliyuncs.com");
        request.setVersion("2017-05-25");
        request.setAction("SendSms");
        request.putQueryParameter("RegionId", "cn-hangzhou");
        request.putQueryParameter("PhoneNumbers", PhoneNumbers);
        request.putQueryParameter("SignName", "乔木健康");
        request.putQueryParameter("TemplateCode", templateCode);
        request.putQueryParameter("TemplateParam",  "{\"code\":" + code + "}");
        try {
            CommonResponse response = client.getCommonResponse(request);
            System.out.println(response.getData());
        } catch (ServerException e) {
            e.printStackTrace();
        } catch (ClientException e) {
            e.printStackTrace();
        }
    }


}
/**
 *
 *
 * */
//    public static void sendVerificationCode(String telephoneNumber,String templateCode,String code) {
//
//        DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "LTAI4Fd6SYeAqguQZppaNps7", "lNDcSzfE23VT2iVjhp2FGihdNDuFbU");
//        IAcsClient client = new DefaultAcsClient(profile);
//
//        CommonRequest request = new CommonRequest();
//        request.setMethod(MethodType.POST);
//        request.setDomain("dysmsapi.aliyuncs.com");
//        request.setVersion("2017-05-25");
//        request.setAction("SendSms");
//        request.putQueryParameter("RegionId", "cn-hangzhou");
//        request.putQueryParameter("PhoneNumbers", telephoneNumber);
//        request.putQueryParameter("SignName", "乔木健康");
//        request.putQueryParameter("TemplateCode", "SMS_181862539");
//        request.putQueryParameter("TemplateParm", "{\"code\":" + code + "}");
//        try {
//            CommonResponse response = client.getCommonResponse(request);
//            System.out.println(response.getData());
//        } catch (ServerException e) {
//            e.printStackTrace();
//        } catch (ClientException e) {
//            e.printStackTrace();
//        }
//    }


